<style>
.content-group {background:#fff;border-radius: 0.5rem;margin-bottom:0.39rem}
.arrow-text {
	display:inline-block;padding:0.1rem 0.3rem;color:#fff;font-size:0.5rem;background:#ff4e2c;border-radius:0.1rem;
}
.arrow-right {
  display:inline-block;
  width:0px;
  height:0px;
  border-bottom:5px solid transparent;  /* left arrow slant */
  border-top:5px solid transparent; /* right arrow slant */
  border-left:5px solid #ff4e2c; /* bottom, add background color here */
  font-size:0px;
  line-height:0px;
  margin-bottom:-1px
}
.fui-navbar .cartbtn {padding-right:0.3rem;background:#fff;opacity:1}
.fui-navbar .buybtn  {padding-left:0.3rem;background:#fff}
.fee-tag-nav, .fee-tagup-nav, .fee-disabled-nav {border-radius:1rem;height:2rem;line-height:2rem;color:#fff;width:100%;font-weight:400;font-size:0.7rem;margin:0.2rem 0;padding:0 0.2rem}
.fee-tagup {background:{{main.syscolor || 'red'}};color:#fff;width:auto;font-weight:400;font-size:0.55rem}
.fee-tag-nav {background:{{main.syscolor || 'red'}}; opacity: 0.58;}
.fee-tagup-nav {background:{{main.syscolor || 'red'}};}
</style>
<div class="fui-page fui-page-current page-goods-list">
<div class='fui-content'>
		<div style="padding:0 0.5rem">
		<div class="fui-cell-group" style="padding:0.5rem;border-radius:0.5rem">
			<div class="fui-cell">
				<div class="fui-cell-label c" style="width:2.5rem">
					<div style="border-radius: 50%;background:#63BE72;width:2rem;height:2rem;line-height:2rem;color:#fff">
						寄
					</div>
				</div>
				<div ng-if="!pagedata.post.address.name" ng-click="pagedata.nowtype=1;pagedata.address={};pagedata.edit_address=true" class="fui-cell-info bold">
					新建寄件人
				</div>
				<div ng-if="pagedata.post.address.name" class="fui-cell-info">
				<div class="fui-cell" style="padding:0;padding-bottom:0.1rem">
					<div style="width:100%">
						<div class="fui-cell-text name bold" style="font-size:0.8rem">
							<span style="margin-right:20px">{{pagedata.post.address.name}}</span><span>{{pagedata.post.address.mobile}}</span>
						</div>
						<div class="fui-cell-text name" style="margin-top:5px;color:#999;font-size:0.6rem">	
							{{pagedata.post.address.pcd.province||''}} {{pagedata.post.address.pcd.city ||''}} {{pagedata.post.address.pcd.district||''}} {{pagedata.post.address.address ||''}}
						</div>
					</div>
				</div>
				</div>
				<div class="fui-cell-remark noremark" style="width:2rem;line-height:1.2" ng-click="pagedata.nowtype=1;pagedata.get_addresslist()">
					<i class="icon icon-tianmaoanshidaohuo" style="font-size:1.3rem;margin:0 0.2rem"></i>
					<div class="gray" style="font-size:0.6rem">地址薄</div>
				</div>
			</div>
			<div class="fui-cell">
				<div class="fui-cell-label c" style="width:2.5rem">
					<div style="border-radius: 50%;background:#4491F1;width:2rem;height:2rem;line-height:2rem;color:#fff">
						收
					</div>
				</div>
				<div ng-if="!pagedata.post.toaddress.name" ng-click="pagedata.nowtype=2;pagedata.address={};pagedata.edit_address=true" class="fui-cell-info bold">
					新建收件人
				</div>
				<div ng-if="pagedata.post.toaddress.name" class="fui-cell-info">
				<div class="fui-cell" style="padding:0;padding-bottom:0.1rem">
					<div style="width:100%">
						<div class="fui-cell-text name bold" style="font-size:0.8rem">
							<span style="margin-right:20px">{{pagedata.post.toaddress.name}}</span><span>{{pagedata.post.toaddress.mobile}}</span>
						</div>
						<div class="fui-cell-text name" style="margin-top:5px;color:#999;font-size:0.6rem">	
							{{pagedata.post.toaddress.pcd.province||''}} {{pagedata.post.toaddress.pcd.city ||''}} {{pagedata.post.toaddress.pcd.district||''}} {{pagedata.post.toaddress.address ||''}}
						</div>
					</div>
				</div>
				</div>
				<div class="fui-cell-remark noremark" style="width:2rem;line-height:1.2" ng-click="pagedata.nowtype=2;pagedata.get_addresslist()">
					<i class="icon icon-tianmaoanshidaohuo" style="font-size:1.3rem;margin:0 0.2rem"></i>
					<div class="gray" style="font-size:0.6rem">地址薄</div>
				</div>
			</div>
		</div>
		<div class="fui-cell-group" style="padding:0.5rem;border-radius:0.5rem">
			<div class="fui-cell-group fui-comment-group" style="padding: 0;background-color: #fff;border-radius: 10px;">
				<div class="fui-cell">
						<div class="fui-cell-text">寄件信息</div>
						<div class="fui-cell-remark" ng-click="pagedata.showwpxx=true" style="color:#61bba7">
							<span class="arrow-text" style="margin-right:-0.25rem">必填</span>
							<span class="arrow-right"></span>
							{{pagedata.post.typetitle}} {{pagedata.post.weight || 1}}KG
						</div>
				</div>
				<div class="fui-cell">
						<div class="fui-cell-text">备注</div>
						<div class="fui-cell-remark" style="color:#61bba7" ng-click="pagedata.showremark=true">
							{{pagedata.post.remark||'选填'}}
						</div>
				</div>
				<div class="fui-cell">
						<div class="fui-cell-text">
							<div class="text">选择快递公司</div>
							<div class="gray">请主动与快递员沟通取件时间</div>
						</div>
						<div class="fui-cell-remark" ng-click="pagedata.selectkd();" style="color:#61bba7">
							{{pagedata.post.priceinfo.tagType || '请选择'}}
						</div>
				</div>
			</div>		
		</div>
		<div ng-include="sys_html('common/_copyright',true)"></div>
		</div>
</div>
<div class="fui-navbar-tip" ng-if="pagedata.pluginset.open_tips==1"><i class="icon icon-information" style="font-size:0.6rem;color:red"></i> {{pagedata.pluginset.tips}}</div>
<div class="fui-navbar order-create-checkout">
    <a ng-if="pagedata.post.endprice>0" href="javascript:;" class="nav-item total" style="text-align:left;padding-left:0.5rem">
        费用:<span class="text-danger bigprice">￥ 
			<span class="totalprice" style="font-size:1.2rem">{{pagedata.post.endprice || '0.00'}}</span>
			<span ng-if="pagedata.post.baoprice>0" class="totalprice" style="font-size:0.6rem">({{pagedata.post.baoprice || '0.00'}})</span>
		</span>
    </a>
	<a ng-if="pagedata.post.endprice<=0" href="javascript:;" class="nav-item total" style="text-align:left;padding-left:0.5rem;color:#666;font-size:0.6rem">
        选择快递公司获取价格
    </a>
	<a ng-if="pagedata.order_id" href="javascript:;" class="nav-item btn buybtn" ng-click="access_json('/ji_log/')" >
		<div class="fee-tagup-nav">
			查看订单
		</div>
	</a>
    <a ng-if="!pagedata.order_id" href="javascript:;" class="nav-item btn buybtn" ng-click="pagedata.pay_submit(pagedata.post,'jy_kuaidisys/ji/post/','/ji_log//fromcreate=1')" >
		<div class="fee-tagup-nav">
			立即下单
		</div>
	</a>
</div>
<div ng-include="sys_html('shop/_remark')"></div>
<div ng-include="sys_html('shop/_wpxx')"></div>
<div ng-include="sys_html('shop/_selectkd')"></div>
<div ng-if="pagedata.modal_address==1" class="popup">
	<div class="popup-body">
		<div class="popup-bottom" style="padding-bottom:2.5rem">
		<i class="closed icon icon-close" style="color:red;top:0.3rem" ng-click="pagedata.modal_address=0"></i>
		<div class="fui-list-group modal-swiper-y" style='margin-top:5px;background:#fff;'>
			<div class="fui-list address-item" ng-repeat="item in pagedata.address_list">
				<div class="fui-list-inner">
					<div class="title" ng-click="pagedata.change_address(item)"><span class='realname'>{{item.name}}</span> <span class='mobile'>{{item.mobile}}</span></div>
					<div class="text" ng-click="pagedata.change_address(item)"><span class='address'>{{item.pcd.province}} {{item.pcd.city}} {{item.pcd.district}} {{item.address}}</span></div>
					<div class='bar' style="line-height:1.4">
						<span class='pull-right'>
							<a class="external" href="javascript:;" ng-click="pagedata.edit_address=1;pagedata.address=item;pagedata.isaddaddress=0">
							<i class='icon icon-bianji'></i> 编辑
							</a>
							<a class='external' href="javascript:;" ng-click="pagedata.del_address($index)">
							<i class='icon icon-shanchu'></i> 删除
							</a>
						</span>
					</div>
				</div>
			</div>
		</div>
		<div class='fui-navbar' style="padding:0.4rem 1rem">
			<a class="btn btn-danger btn-banf" style="margin:0;width:100%" ng-click="pagedata.edit_address=1;pagedata.address={};pagedata.isaddaddress=1"><i class="icon icon-tianjia" style="font-size:0.8rem"></i> 添加地址</a>
		</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.edit_address" class="popup">
	<div class="popup-body">
		<div class="popup-bottom">
			<div class='fui-cell-group modal-swiper-y' style="border-radius: 0.5rem;margin-top:0;height:auto;max-height:23rem;min-height:20rem;padding-bottom:3.5rem">
				<div ng-if="pagedata.nowtype==1" class="fui-cell">
					<div class="fui-cell-label" style="width:100px;font-size:0.8rem">编辑地址</div>
					<div class='fui-cell-info'></div>
					<div class="fui-cell-remark" ng-if="pagedata.openid && pagedata.isaddaddress==1"><span ng-click="pagedata.openAddress()">添加微信地址</span></div>
				</div>
				<div ng-if="!pagedata.address.id && pagedata.jy_aiaddress.isopen==1" class="fui-cell">
					<div class="fui-cell-info c000">
						<textarea rows="2" placeholder="请输入要解析的地址" ng-model="pagedata.address.apiaddress"></textarea>
						<div ng-click="pagedata.jieaddress();" class="label label-success" style="position: absolute;right:1rem;bottom:1.3rem">解析地址</div>
					</div>
				</div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>{{pagedata.nowtype==1?'寄件人':'收件人'}}</div>
                    <div class='fui-cell-info'><input type="text" ng-model="pagedata.address.name" placeholder="{{pagedata.nowtype==1?'寄件人':'收件人'}}" class="fui-input"/></div>
                </div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>联系电话</div>
                    <div class='fui-cell-info'><input type="tel" ng-model="pagedata.address.mobile" placeholder="联系电话"  class="fui-input"/></div>
                </div>
                <div class="fui-cell">
					<div class="fui-cell-label" style="width:2.3rem">地区</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.address.pcd.province" class="form-control tpl-province">
						<option value="" selected="selected">省份</option>
						<option ng-repeat="(value,data) in pagedata.province" value="{{value}}" ng-selected="pagedata.address.pcd.province==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.address.pcd.city" class="form-control tpl-city">
						<option value="" selected="selected">城市</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.address.pcd.province]" value="{{value}}" ng-selected="pagedata.address.pcd.city==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.address.pcd.district" class="form-control tpl-district">
						<option value="" selected="selected">区县</option>
						<option ng-repeat="(value,data) in pagedata.province[pagedata.address.pcd.province][pagedata.address.pcd.city]" value="{{value}}" ng-selected="pagedata.address.pcd.district==value">{{value}}</option>
						</select>
					</div>
					<div class="fui-cell-label" style="width:28%">
						<select ng-model="pagedata.address.pcd.street" class="form-control tpl-district">
						<option value="" selected="selected">街道</option>
						<option ng-repeat="value in pagedata.province[pagedata.address.pcd.province][pagedata.address.pcd.city][pagedata.address.pcd.district]" value="{{value}}" ng-selected="pagedata.address.pcd.street==value">{{value}}</option>
						</select>
					</div>
				</div>
                <div class='fui-cell'>
                    <div class='fui-cell-label'>详细地址</div>
                    <div class='fui-cell-info'>
						<textarea rows="2" placeholder="街道，楼牌号等" ng-model="pagedata.address.address"></textarea>
					</div>
                </div>
            </div>
			<div class="fui-navbar" style="padding:0.35rem 1rem">
				<a href="javascript:;" ng-click="pagedata.add_address();" class="btn btn-danger btn-banf" style="margin:0;width:100%">确定</a>
			</div>
			<i ng-click="pagedata.edit_address=false" class="closed icon icon-cuowu"></i>
		</div>
	</div>
</div>
</div>
<script>
scope.pagedata.pay_submit=function(post,post_url,complete_url){
	if(scope.pagedata.post.endprice<=0){
		scope.message('请选择快递公司！','error');
		return false;
	}
	scope.post_json(post_url,post,function(result){
		scope.pagedata.order_id=result.order_id;
		var success_url=result.success_url?result.success_url:complete_url
		var error_url=result.error_url?result.error_url:complete_url
		scope.$evalAsync();
		scope.tool.pay(result.pay_id,function(res){
				if(res.type=='success'){
					scope.message('支付成功！','success',success_url);
				}else{
					scope.message('支付失败！','success',error_url);
				}
		},'','',success_url,error_url);
	});
}
scope.pagedata.add_address=function(){
	scope.pagedata.address.res=1
	if(scope.pagedata.isaddaddress==1){
		scope.pagedata.address.id=0;
	}
	scope.post_json('jy_kuaidisys/member.address/post/type='+scope.pagedata.nowtype,scope.pagedata.address,function(res){
		scope.pagedata.post.addressid =res;
		scope.pagedata.edit_address=false;
		scope.pagedata.modal_address=0;
		if(scope.pagedata.nowtype==1){
			scope.pagedata.post.address=scope.pagedata.address;
		}else{
			scope.pagedata.post.toaddress=scope.pagedata.address;
		}
		scope.$evalAsync();
	});
}
scope.pagedata.change_address=function(res){
	if(scope.pagedata.nowtype==1){
		scope.pagedata.post.address=res;
	}else{
		scope.pagedata.post.toaddress=res;
	}
	scope.pagedata.post.addressid=res.id;
	scope.pagedata.modal_address=0;
	scope.$evalAsync();
}
scope.pagedata.get_addresslist=function(){
	scope.get('jy_kuaidisys/member.address/list/type='+scope.pagedata.nowtype,function(res){
		scope.pagedata.address_list=res.list;
		scope.pagedata.modal_address=1;
		scope.$evalAsync();	
	});
}
scope.pagedata.del_address=function(index){
	var id =scope.pagedata.address_list[index].id
	scope.get('jy_kuaidisys/member.address/del/id='+id+'&get=1',function(res){
		scope.pagedata.address_list.splice(index,1);
		scope.message('删除成功');
		scope.$evalAsync();
	});
}
scope.pagedata.openAddress=function (){
	wx.openAddress({
		  success: function (res) {
			scope.pagedata.address={}
			scope.pagedata.address.name = res.userName; // 收货人姓名
			scope.pagedata.address.pcd={}
			scope.pagedata.address.pcd.province = res.provinceName; // 国标收货地址第一级地址（省）
			scope.pagedata.address.pcd.city = res.cityName; // 国标收货地址第二级地址（市）
			scope.pagedata.address.pcd.district = res.countryName; // 国标收货地址第三级地址（国家）
			scope.pagedata.address.address = res.detailInfo; // 详细收货地址信息
			scope.pagedata.address.mobile = res.telNumber; // 收货人手机号码
			scope.$evalAsync();
		  },
		  fail: function (res) {
			console.log('fail');console.log(res)
		  }
	});
}
scope.pagedata.selectkd=function(){
	if(!scope.pagedata.post.address || !scope.pagedata.post.address.name || !scope.pagedata.post.address.mobile || !scope.pagedata.post.address.address || !scope.pagedata.post.address.pcd.province || !scope.pagedata.post.address.pcd.city || !scope.pagedata.post.address.pcd.district){
		scope.message('寄件人地址不完善！');
		return false;
	}
	if(!scope.pagedata.post.toaddress || !scope.pagedata.post.toaddress.name || !scope.pagedata.post.toaddress.mobile || !scope.pagedata.post.toaddress.address || !scope.pagedata.post.toaddress.pcd.province || !scope.pagedata.post.toaddress.pcd.city || !scope.pagedata.post.toaddress.pcd.district){
		scope.message('寄件人地址不完善！');
		return false;
	}
	scope.post_json('jy_kuaidisys/ji/getfeekd/',scope.pagedata.post,function(res){
		scope.pagedata.kdlist=res.list;
		scope.pagedata.showwselectkd=true
		scope.$evalAsync();
	});
}
scope.pagedata.getfee=function(){
	scope.pagedata.post.endprice=0;
	scope.pagedata.post.express_id='';
}
scope.pagedata.jieaddress=function(){
	scope.post_json('jy_aiaddress/get_data/jieaddress/',scope.pagedata.address,function(res){
		console.log(res);
		if(res.jieaddress){
			scope.pagedata.address=res.jieaddress;
			scope.$evalAsync();
		}
	});
}
scope.pagedata.getprovince=function(){
	scope.get('core/member.set/getprovince/',function(res){
		scope.pagedata.province=res.province;
		scope.$evalAsync();
	});
}
scope.pagedata.getprovince();
</script>